<style>
    .form-group label{width:100px}
    .task .form-group{width: 95%;float: left;}
</style>
<section class="content task" >
    <div class="row">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body">
                    <form id="site_public_editinfo_form">
                        <input type="hidden" name="id" value="{$data.id}" />
                        <div class="form-group">
                            <label style="display:inline-table">装料站
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <select class="form-control " data-placeholder="请输入装料站名称" style="width: 70%"
                                    name="site_id">
                                <option value="{$data['site_id']}" selected>{$data['task_from']}</option>
                            </select>
                        </div>
                            <input type="hidden" id="sitelonglat" />
                        <div class="form-group">
                            <label style="display:inline-table;width: 130px" >装料站联系电话
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" placeholder="装料站联系电话"
                                   class="form-control" data-validation="length"
                                   data-validation-length="min1"
                                   name="site_mobile" value="{$data.site_mobile}"
                                   data-validation-error-msg="请输入装料站联系电话"
                                   style="display:inline;width: 70%">
                        </div>
                        <div class="form-group" >
                            <label style="display:inline-table">抵达地址
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" placeholder="请输入抵达地址"
                                   class="form-control"
                                   id="task_end"
                                   name="task_end" value="{$data.task_end}"
                                   style="display:inline;width: 40%">
                            <input id="task_end_latgong" name="task_end_latgong"  class="form-control" style="display:inline;width: 35%"
                                   value="{$data.task_end_longitude|default=0},{$data.task_end_latitude|default=0}" readonly onclick="getLocal()" />
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">联系人
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" placeholder="请输入联系人"
                                   class="form-control"  data-validation="length"
                                   data-validation-length="min1"
                                   name="linkman"  id="linkman" value="{$data.linkman}"
                                   data-validation-error-msg="请输入联系人"
                                   style="display:inline;width: 70%">
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">联系电话
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" placeholder="请输入联系电话"
                                   class="form-control"  data-validation="length"
                                   data-validation-length="min1"
                                   name="mobile" id="mobile" value="{$data.mobile}"
                                   data-validation-error-msg="请输入联系电话"
                                   style="display:inline;width: 70%">
                        </div>
                        <!--<div class="form-group">-->
                            <!--<label style="display:inline-table">保底方量-->
                                <!--<i class="fa fa-pencil-square-o"></i>:</label><br/>-->
                            <!--<foreach name="car_load" item="vo" key="k">-->
                                <!--{$vo}方车保底-->
                                <!--<input type="text" value="{$def_load[$k]}" name="def_load[{$k}]"  />方<br/>-->
                            <!--</foreach>-->
                        <!--</div>-->
                        <!--<div class="form-group">-->
                            <!--<label style="display:inline-table">价格区间-->
                                <!--<i class="fa fa-pencil-square-o"></i>:</label><br/>-->
                            <!--<if condition='$def_price'>-->
                            <!--<foreach name="def_price" item="vo" key="k">-->
                                <!--<div class="row">-->
                                    <!--<input type="text" value="{$def_price[$k][0]}" name="def_price[{$k}][0]"  style="width: 20%"/> - -->
                                    <!--<input type="text"  value="{$def_price[$k][1]}" name="def_price[{$k}][1]" style="width: 20%"/>公里-->
                                    <!--<input type="text"  value="{$def_price[$k][2]}" name="def_price[{$k}][2]"style="width: 20%"/>元-->
                                <!--</div>-->
                            <!--</foreach>-->
                                <!--<else/>-->
                                <!--<div class="row">-->
                                    <!--<input type="text" value="" name="def_price[0][0]"  style="width: 20%"/> - -->
                                    <!--<input type="text"  value="" name="def_price[0][1]" style="width: 20%"/>公里-->
                                    <!--<input type="text"  value="" name="def_price[0][2]" style="width: 20%"/>元-->
                                <!--</div>-->
                                <!--</if>-->
                            <!--<button class="btn btn-danger pull-right" type="button" id="addMore">+更多</button>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label style="display:inline-table">状态
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <label>
                                <input type="radio" value="0" name="status"
                                <eq name="data['status']" value="0"> checked="checked"</eq>
                                <eq name="data['status']" value=""> checked="checked"</eq>
                                >&nbsp;&nbsp;启用
                            </label>
                            <label>
                                <input type="radio" value="1" name="status"
                                <eq name="data['status']" value="1"> checked="checked"</eq>
                                >&nbsp;&nbsp;停用
                            </label>
                        </div>
                        <div style="clear: both;"></div>
                        <div class="box-footer">
                            <span class="input-group-btn">
                                <button class="btn btn-danger pull-left" type="button"  id="close-dialog">取消</button>
                                <button class="btn btn-primary pull-right" type="button" id='site_public_editinfo_form_submit'>提交</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function formatRepo(data) {
            if (data.id === '') { // adjust for custom placeholder values
                return '请输入装料站名称';
            }
            $("#sitelonglat").val(data.longitude+','+data.latitude)
            return data.name;
        }
        function formatRepoSelection(data, container) {
            return data.name;
        }
        $(function () {
            $('.date').datepicker({language:'zh-CN','autoclose':true});
            $(".select2").select2({minimumResultsForSearch: -1});
            $("select[name='site_id']").select2({
                placeholder: "请输入装料站名称",
                allowClear: true,
                ajax: {
                    url: "{:U('Site/search')}",
                    dataType: 'json',
                    delay: 300,
                    data: function (params) {
                        return {
                            key: params.term, // search term
                            page: params.page
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.items,
                            pagination: {
                                more: (params.page * 30) < data.total_count
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
            $('#site_public_editinfo_form_submit').click(function () {
                $('#site_public_editinfo_form').submit();
            });
            $.validate({
                onSuccess: function () {
                    publicEditinfoFormSubmit();
                    return false;
                }
            });
            $(".task .select2-selection__rendered").append("{$data['task_from']}");
            $("#sitelonglat").val('{$data["task_from_longitude"]},{$data["task_from_latitude"]}')
        });

        function publicEditinfoFormSubmit() {
            $.post("{:U('Task/addRoads')}",
                    $("#site_public_editinfo_form").serialize(), function (res) {
                if (!res.status) {
                    $.messager.alert('提示信息', res.info, 'error');
                } else {
                    $.messager.alert('提示信息', res.info, 'info');
                    dialog.get('dialogPage').close().remove();
                    taskTable.fnDraw(false);
                }
            });
            return false;
        }

        function getLocal(){
            var lonlat = $("#task_end_latgong").val();
            var lons = lonlat.split(',');
            var url = '{:U("Task/taskEnd")}?lng='+lons[0]+"&lat="+lons[1]+"&address="+$('#task_end').val();
            $.dialog(url, '抵达地址', null,46,'getLonlat');
        }
    </script>
</section>